package ddb.dbcore;

import java.sql.*;

public class DbConnection {
    private static String conString = "jdbc:mysql://localhost/shopinfo";
    private static String user = "root";
    private static String passwd = "111111";
    
    public static Connection getDBConnection() {
        Connection conn = null;
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            conn = DriverManager.getConnection(conString,user,passwd);
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }
        return conn;
    }
    
    public static void closeConnection(Connection conn) {
        try {
            if (conn != null)
                conn.close();
        }
        catch (Exception ex) {
            System.out.println(ex.toString());
        }
        
    }
    
    public DbTable getResult() {
        DbTable table = null;
        DbManager dbm = new DbManager();
        try {
            //long time1 = System.currentTimeMillis();
            for (int j = 0; j < 50; j ++) {
                table = dbm.executeSelect(String.format("select * from inventory where id = %d", j));
            }
            
            //long time2 = System.currentTimeMillis();
            //System.out.println("rdsc : " + (double)500/(time2 - time1)*1000);
        }
        catch (Exception ex) {
            System.out.println(ex.toString());
        }
        
        return table;
    }
}
